package com.crl.module.loaders
{
	import com.crl.module.loaders.workers.ILoadWorker;

	public class MultiQueueWorker extends AbstractQueueWorker implements ILoadWorker ,IQueueWorkerListener
	{
		
		private var queue:Vector.<IQueueWorker>;
		
		private var queueLoaded:int;
		private var queueTotal:int;
		
		public function MultiQueueWorker(queue:Vector.<IQueueWorker>)
		{
			this.queue=queue;
			
			this.loaded=0;
			this.total=0;
			this.queueLoaded=0;
			this.queueTotal=this.queue.length;
			
			for each(var item:IQueueWorker in queue){
				item.workListener=this;
				
				loaded+=item.itemTotal;
			}
		}
		
		override public function start():void
		{
			
			for each(var item:IQueueWorker in queue){
				item.start();
			}
		}
		
		
		
			
		public function onItemComplete(loader:IQueueWorker,data:*,index:int):void{
			loaded++;
		}
		
		
		/**
		 * 提供参数以知道下载进度; 
		 * @param loader
		 * @param bytesLoaded
		 * @param bytesTotal
		 * @param index
		 * @param total
		 * 
		 */		
		public function onQueueProgress(loader:IQueueWorker,bytesLoaded:int,bytesTotal:int,index:int,total:int):void{
			
		}
		
		/**
		 * 所有内容加载完毕; 
		 * @param loader
		 * @param datas
		 * 
		 */		
		public function onQueueComplete(loader:IQueueWorker,datas:Array):void{
			queueLoaded++;
		}
		
		public function onQueueSecurityError(loader:IQueueWorker,message:String):void{
		}
		
		public function onQueueIOError(loader:IQueueWorker,index:int,message:String):void{
			
		}
		
		
	}
}